package com.ruoyi.patrol.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.task.PatrolJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.patrol.mapper.PatrolPlanMapper;
import com.ruoyi.patrol.domain.PatrolPlan;
import com.ruoyi.patrol.service.IPatrolPlanService;

/**
 * 巡查计划Service业务层处理
 * 
 * @author yepanpan
 * @date 2025-05-08
 */
@Service
public class PatrolPlanServiceImpl implements IPatrolPlanService 
{
    private static final Logger log = LoggerFactory.getLogger(PatrolPlanServiceImpl.class);

    @Autowired
    private PatrolPlanMapper patrolPlanMapper;
    @Autowired
    private ISysUserService userService;
    @Autowired
    private PatrolJob patrolJob;

    /**
     * 查询巡查计划
     * 
     * @param id 巡查计划主键
     * @return 巡查计划
     */
    @Override
    public PatrolPlan selectPatrolPlanById(Long id)
    {
        return patrolPlanMapper.selectPatrolPlanById(id);
    }

    /**
     * 查询巡查计划列表
     * 
     * @param patrolPlan 巡查计划
     * @return 巡查计划
     */
    @Override
    public List<PatrolPlan> selectPatrolPlanList(PatrolPlan patrolPlan)
    {
        return patrolPlanMapper.selectPatrolPlanList(patrolPlan);
    }

    /**
     * 新增巡查计划
     * 
     * @param patrolPlan 巡查计划
     * @return 结果
     */
    @Override
    public int insertPatrolPlan(PatrolPlan patrolPlan)
    {
        SysUser sysUser = userService.selectUserById(patrolPlan.getUserId());
        patrolPlan.setUserName(sysUser.getNickName());
        patrolPlan.setCreateTime(DateUtils.getNowDate());
        int ret = patrolPlanMapper.insertPatrolPlan(patrolPlan);
        patrolJob.genTask();
        return ret;
    }

    /**
     * 修改巡查计划
     * 
     * @param patrolPlan 巡查计划
     * @return 结果
     */
    @Override
    public int updatePatrolPlan(PatrolPlan patrolPlan)
    {
        SysUser sysUser = userService.selectUserById(patrolPlan.getUserId());
        patrolPlan.setUserName(sysUser.getNickName());
        patrolPlan.setUpdateTime(DateUtils.getNowDate());
        int ret = patrolPlanMapper.updatePatrolPlan(patrolPlan);
        patrolJob.genTask();
        return ret;
    }

    /**
     * 批量删除巡查计划
     * 
     * @param ids 需要删除的巡查计划主键
     * @return 结果
     */
    @Override
    public int deletePatrolPlanByIds(Long[] ids)
    {
        return patrolPlanMapper.deletePatrolPlanByIds(ids);
    }

    /**
     * 删除巡查计划信息
     * 
     * @param id 巡查计划主键
     * @return 结果
     */
    @Override
    public int deletePatrolPlanById(Long id)
    {
        return patrolPlanMapper.deletePatrolPlanById(id);
    }


}
